﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.Materials;
using THE_WIND_RISES.Common.Dtos;
namespace Production_Get.API.Application.Commands.WorkCenter_W
{
    /// <summary>
    /// 物料绑定下拉框
    /// </summary>
    public class ItemInfoShowHandler1 : IRequestHandler<ItemInfoShowCommand1, Result>
    {
        private readonly IBaseRepositoryGet<ItemInfo> ItemInfoRepository;

        public ItemInfoShowHandler1(IBaseRepositoryGet<ItemInfo> itemInfoRepository)
        {
            ItemInfoRepository = itemInfoRepository;
        }

        public async Task<Result> Handle(ItemInfoShowCommand1 request, CancellationToken cancellationToken)
        {
            var result = new THE_WIND_RISES.Common.Dtos.Result() { Code = (int)CommonErrorCodes.Search };
            try
            {
                var sql1 = "select * from ItemInfo";
                var list = from a in ItemInfoRepository.GetAll(sql1)
                           select new
                           {
                               a.InventoryInfoId,
                               a.ItemName
                           };
                result.Data = list;
            }
            catch (Exception ex)
            {
                throw;
            }
            return result;
        }
    }
}
